home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / pt-plot.h < prev    next >
C/C++ Source or Header  |  1996-11-20  |  7KB  |  329 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_tree_plot_h)
  24. #define octave_tree_plot_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. class ostream;
  31. class ostrstream;
  32.  
  33. class tree_command;
  34. class tree_plot_command;
  35. class plot_limits;
  36. class plot_range;
  37. class subplot_using;
  38. class subplot_style;
  39. class subplot;
  40. class subplot_list;
  41.  
  42. class tree_walker;
  43.  
  44. #include <csignal>
  45.  
  46. #include <string>
  47.  
  48. #include <SLList.h>
  49.  
  50. #include "dColVector.h"
  51.  
  52. #include "idx-vector.h"
  53. #include "pt-cmd.h"
  54. #include "pt-exp.h"
  55.  
  56. class
  57. tree_plot_command : public tree_command
  58. {
  59. public:
  60.  
  61.   tree_plot_command (subplot_list *plt = 0, plot_limits *rng = 0, int nd = 0)
  62.     : tree_command (), ndim (nd), range (rng), plot_list (plt) { }
  63.  
  64.   ~tree_plot_command (void);
  65.  
  66.   void eval (void);
  67.  
  68.   int num_dimensions (void) { return ndim; }
  69.  
  70.   plot_limits *limits (void) { return range; }
  71.  
  72.   subplot_list *subplots (void) { return plot_list; }
  73.  
  74.   void accept (tree_walker& tw);
  75.  
  76. private:
  77.  
  78.   // The number of dimensions.  1 indicates a replot command.
  79.   int ndim;
  80.  
  81.   // The data ranges for the plot.
  82.   plot_limits *range;
  83.  
  84.   // The list of plots for this plot command.  For example, the
  85.   // command "plot sin(x), cos(x)" has two subplot commands.
  86.   subplot_list *plot_list;
  87. };
  88.  
  89. class
  90. plot_limits
  91. {
  92. public:
  93.  
  94.   plot_limits (plot_range *xlim = 0, plot_range *ylim = 0,
  95.            plot_range *zlim = 0)
  96.     : x_range (xlim), y_range (ylim), z_range (zlim) { }
  97.  
  98.   ~plot_limits (void);
  99.  
  100.   void print (int ndim, ostrstream& plot_buf);
  101.  
  102.   plot_range *x_limits (void) { return x_range; }
  103.   plot_range *y_limits (void) { return y_range; }
  104.   plot_range *z_limits (void) { return z_range; }
  105.  
  106.   void accept (tree_walker& tw);
  107.  
  108. private:
  109.  
  110.   // Specified limits of the x, y, and z axes we should display for
  111.   // this plot.
  112.   plot_range *x_range;
  113.   plot_range *y_range;
  114.   plot_range *z_range;
  115. };
  116.  
  117. class
  118. plot_range
  119. {
  120. public:
  121.  
  122.   plot_range (tree_expression *l = 0, tree_expression *u = 0)
  123.     : lower (l), upper (u) { }
  124.  
  125.   ~plot_range (void);
  126.  
  127.   void print (ostrstream& plot_buf);
  128.  
  129.   tree_expression *lower_bound (void) { return lower; }
  130.  
  131.   tree_expression *upper_bound (void) { return upper; }
  132.  
  133.   void accept (tree_walker& tw);
  134.  
  135. private:
  136.  
  137.   // A range can specify a lower or upper bound or both.  If neither
  138.   // is specified, the range to display is determined from the data.
  139.   tree_expression *lower;
  140.   tree_expression *upper;
  141. };
  142.  
  143. class
  144. subplot_using
  145. {
  146. public:
  147.  
  148.   subplot_using (tree_expression *fmt = 0)
  149.     : qual_count (0), scanf_fmt (fmt), val (4, -1)
  150.       {
  151.     x[0] = x[1] = x[2] = x[3] = 0;
  152.       }
  153.  
  154.   ~subplot_using (void);
  155.  
  156.   subplot_using *set_format (tree_expression *fmt)
  157.     {
  158.       scanf_fmt = fmt;
  159.       return this;
  160.     }
  161.  
  162.   subplot_using *add_qualifier (tree_expression *t)
  163.     {
  164.       if (qual_count < 4)
  165.     x[qual_count] = t;
  166.  
  167.       qual_count++;
  168.  
  169.       return this;
  170.     }
  171.  
  172.   int eval (int ndim, int n_max);
  173.  
  174.   ColumnVector values (int ndim, int n_max = 0);
  175.  
  176.   int print (int ndim, int n_max, ostrstream& plot_buf);
  177.  
  178.   int qualifier_count (void) { return qual_count; }
  179.  
  180.   tree_expression **qualifiers (void) { return x; }
  181.  
  182.   tree_expression *scanf_format (void) { return scanf_fmt; }
  183.  
  184.   void accept (tree_walker& tw);
  185.  
  186. private:
  187.  
  188.   // The number of using qualifiers (in "using 1:2", 1 and 2 are the
  189.   // qualifiers).
  190.   int qual_count;
  191.  
  192.   // An optional scanf-style format.  This is parsed and stored but
  193.   // not currently used.
  194.   tree_expression *scanf_fmt;
  195.  
  196.   // This is a cache for evaluated versions of the qualifiers stored
  197.   // in x.
  198.   ColumnVector val;
  199.  
  200.   // A vector to hold using qualifiers.
  201.   tree_expression *x[4];
  202. };
  203.  
  204. class
  205. subplot_style
  206. {
  207. public:
  208.  
  209.   subplot_style (const string& s = string (),
  210.          tree_expression *lt = 0, tree_expression *pt = 0)
  211.     : sp_style (s), sp_linetype (lt), sp_pointtype (pt) { }
  212.  
  213.   ~subplot_style (void);
  214.  
  215.   int print (ostrstream& plot_buf);
  216.  
  217.   bool columns_ok (int nc);
  218.  
  219.   string style (void) { return sp_style; }
  220.  
  221.   tree_expression *linetype (void) { return sp_linetype; }
  222.  
  223.   tree_expression *pointtype (void) { return sp_pointtype; }
  224.  
  225.   void accept (tree_walker& tw);
  226.  
  227. private:
  228.  
  229.   // The style we are using: `lines', `points', etc.
  230.   string sp_style;
  231.  
  232.   // The number of the line type to use.
  233.   tree_expression *sp_linetype;
  234.  
  235.   // The number of the point type to use.
  236.   tree_expression *sp_pointtype;
  237. };
  238.  
  239. class
  240. subplot
  241. {
  242. public:
  243.  
  244.   subplot (tree_expression *data = 0)
  245.     : sp_plot_data (data), sp_using_clause (0), sp_title_clause (0),
  246.       sp_style_clause (0) { }
  247.  
  248.   subplot (subplot_using *u, tree_expression *t, subplot_style *s)
  249.     : sp_plot_data (0), sp_using_clause (u), sp_title_clause (t),
  250.       sp_style_clause (s) { }
  251.  
  252.   ~subplot (void);
  253.  
  254.   subplot *set_data (tree_expression *data)
  255.     {
  256.       sp_plot_data = data;
  257.       return this;
  258.     }
  259.  
  260.   octave_value extract_plot_data (int ndim, octave_value& data);
  261.  
  262.   int handle_plot_data (int ndim, ostrstream& plot_buf);
  263.  
  264.   int print (int ndim, ostrstream& plot_buf);
  265.  
  266.   tree_expression *plot_data (void) { return sp_plot_data; }
  267.  
  268.   subplot_using *using_clause (void) { return sp_using_clause; }
  269.  
  270.   tree_expression *title_clause (void) { return sp_title_clause; }
  271.  
  272.   subplot_style *style_clause (void) { return sp_style_clause; }
  273.  
  274.   void accept (tree_walker& tw);
  275.  
  276. private:
  277.  
  278.   // The data to plot.
  279.   tree_expression *sp_plot_data;
  280.  
  281.   // The `using' option
  282.   subplot_using *sp_using_clause;
  283.  
  284.   // The `title' option
  285.   tree_expression *sp_title_clause;
  286.  
  287.   // The `style' option
  288.   subplot_style *sp_style_clause;
  289. };
  290.  
  291. class
  292. subplot_list : public SLList<subplot *>
  293. {
  294. public:
  295.  
  296.   subplot_list (void)
  297.     : SLList<subplot *> () { }
  298.  
  299.   subplot_list (subplot *t)
  300.     : SLList<subplot *> () { append (t); }
  301.  
  302.   ~subplot_list (void);
  303.  
  304.   int print (int ndim, ostrstream& plot_buf);
  305.  
  306.   void accept (tree_walker& tw);
  307. };
  308.  
  309. extern string save_in_tmp_file (octave_value& t, int ndim = 2,
  310.                 bool parametric = false);
  311.  
  312. extern void mark_for_deletion (const string&);
  313.  
  314. extern void cleanup_tmp_files (void);
  315.  
  316. extern void close_plot_stream (void);
  317.  
  318. extern void do_external_plotter_cd (const string& newdir);
  319.  
  320. extern void symbols_of_pt_plot (void);
  321.  
  322. #endif
  323.  
  324. /*
  325. ;;; Local Variables: ***
  326. ;;; mode: C++ ***
  327. ;;; End: ***
  328. */
  329.